package cn.edu.scau.cmi.hekaimin.singleton;

import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;

import javafx.scene.control.TextField;

public class SingletonController {
	@FXML
	private TextField text_1;
	@FXML
	private Button btn_1;
	@FXML
	private Button btn_2;
	private int flag = 0;//判断是否第一次创建
	private ChairmanMao man = null;
	
	@FXML
	public void eventButton1() {

		Alert alert = new Alert(AlertType.INFORMATION);
		alert.titleProperty().set("信息");
		if(text_1.getText().length() == 0) {
			alert.headerTextProperty().set("输入框不能为空!");
		}
		else if(flag == 0 ) {
		man = ChairmanMao.getInstance(text_1.getText());
		alert.headerTextProperty().set("创建主席: " + man.getName()+",成功!");
		flag = 1;
		}else {
			alert.headerTextProperty().set("主席已创建!");	
		}
		alert.showAndWait();

	}
	@FXML
	public void eventButton2() {
		Alert alert = new Alert(AlertType.INFORMATION);
		alert.titleProperty().set("信息");
		if(man == null)
		    alert.headerTextProperty().set("当前主席未创建!");
		else
			alert.headerTextProperty().set("当前主席为: "+ChairmanMao.getName());	
		alert.showAndWait();
	}

}
